/////////////////////////////////////////////////////////////////////////////
// Name:        wxauipanel.cpp
// Purpose:     
// Author:      Stephen Whittle
// Modified by: 
// Created:     08/06/2009 21:31:02
// RCS-ID:      
// Copyright:   
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
#include "quickconnect.h"
#include "preferences.h"
#include "windowfilters.h"
#include "ftpeditor.h"
#include "wxmudauinotebook.h"
////@end includes
#include "globals.h"
#include "wxauipanel.h"
#include "wixtin.h"
#include "wixtin_auiapp.h"
#include "wx/stdpaths.h"
#include "wx/filename.h"
#include <wx/socket.h>
#include "libtelnet.h"
#include <wx/tokenzr.h>
#include <wx/textdlg.h>
#include "wxmudtextctrl.h"
#include "wxmudcommandline.h"
////@begin XPM images
#include "images/connect.xpm"
#include "images/connect_greyed.xpm"
#include "images/disconnect.xpm"
#include "images/disconnect_greyed.xpm"
#include "images/cog.xpm"
#include "images/add_top.xpm"
#include "images/add_bottom.xpm"
#include "images/add_float.xpm"
#include "images/filter.xpm"
#include "images/runprog.xpm"
#include "images/gauges.xpm"
#include "nfs_mount.xpm"
////@end XPM images
  


/*
 * wxAuiPanel type definition
 */

IMPLEMENT_DYNAMIC_CLASS( wxAuiPanel, wxPanel )

 
/*
 * wxAuiPanel event table definition
 */

BEGIN_EVENT_TABLE( wxAuiPanel, wxPanel )

////@begin wxAuiPanel event table entries
    EVT_MENU( ID_TOOL, wxAuiPanel::OnToolClick )

    EVT_MENU( ID_TOOL1, wxAuiPanel::OnDisconnectClick )

    EVT_MENU( ID_TOOL2, wxAuiPanel::OnPrefsClick )

    EVT_MENU( ID_TOOL3, wxAuiPanel::OnAddTopClick )

    EVT_MENU( ID_TOOL4, wxAuiPanel::OnAddBottomClick )

    EVT_MENU( ID_TOOL5, wxAuiPanel::OnNewFloatWindowClick )

    EVT_MENU( ID_TOOL6, wxAuiPanel::OnFilterEditClick )

    EVT_MENU( ID_TOOL16, wxAuiPanel::OnFTPClick )

////@end wxAuiPanel event table entries
    EVT_SOCKET(SOCKET_ID, wxAuiPanel::OnSocketEvent)
END_EVENT_TABLE()


/*
 * wxAuiPanel constructors
 */

wxAuiPanel::wxAuiPanel()
{
    Init();
}

wxAuiPanel::wxAuiPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
    Init();
    Create(parent, id, pos, size, style);
}


/*
 * wxAuiPanel creator
 */

bool wxAuiPanel::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
////@begin wxAuiPanel creation
    wxPanel::Create(parent, id, pos, size, style);
    CreateControls();
////@end wxAuiPanel creation
    return true;
}


/*
 * wxAuiPanel destructor
 */

wxAuiPanel::~wxAuiPanel()
{
////@begin wxAuiPanel destruction
    GetAuiManager().UnInit();
////@end wxAuiPanel destruction
}


/*
 * Member initialisation
 */

void wxAuiPanel::Init()
{
////@begin wxAuiPanel member initialisation
    m_MainToolbar = NULL;
    m_Main = NULL;
    m_Sub = NULL;
////@end wxAuiPanel member initialisation
}


/*
 * Control creation for wxAuiPanel
 */

void wxAuiPanel::CreateControls()
{    
////@begin wxAuiPanel content construction
    wxAuiPanel* itemPanel1 = this;

    GetAuiManager().SetManagedWindow(this);

    m_MainToolbar = new wxAuiToolBar( itemPanel1, ID_TOOLBAR, wxDefaultPosition, wxDefaultSize, wxAUI_TB_TEXT|wxAUI_TB_GRIPPER );
    m_MainToolbar->SetToolBitmapSize(wxSize(16, 16));
    wxBitmap itemtool3Bitmap(itemPanel1->GetBitmapResource(wxT("images/connect.xpm")));
    wxBitmap itemtool3BitmapDisabled(itemPanel1->GetBitmapResource(wxT("images/connect_greyed.xpm")));
    m_MainToolbar->AddTool(ID_TOOL, _("Connect"), itemtool3Bitmap, itemtool3BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    wxBitmap itemtool4Bitmap(itemPanel1->GetBitmapResource(wxT("images/disconnect.xpm")));
    wxBitmap itemtool4BitmapDisabled(itemPanel1->GetBitmapResource(wxT("images/disconnect_greyed.xpm")));
    m_MainToolbar->AddTool(ID_TOOL1, _("Disconnect"), itemtool4Bitmap, itemtool4BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    m_MainToolbar->EnableTool(ID_TOOL1, false);
    wxBitmap itemtool5Bitmap(itemPanel1->GetBitmapResource(wxT("images/cog.xpm")));
    wxBitmap itemtool5BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL2, _("Settings"), itemtool5Bitmap, itemtool5BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    wxBitmap itemtool6Bitmap(itemPanel1->GetBitmapResource(wxT("images/add_top.xpm")));
    wxBitmap itemtool6BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL3, _("New Main Tab"), itemtool6Bitmap, itemtool6BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    wxBitmap itemtool7Bitmap(itemPanel1->GetBitmapResource(wxT("images/add_bottom.xpm")));
    wxBitmap itemtool7BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL4, _("New Sub Tab"), itemtool7Bitmap, itemtool7BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    wxBitmap itemtool8Bitmap(itemPanel1->GetBitmapResource(wxT("images/add_float.xpm")));
    wxBitmap itemtool8BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL5, _("New Floater"), itemtool8Bitmap, itemtool8BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    wxBitmap itemtool9Bitmap(itemPanel1->GetBitmapResource(wxT("images/filter.xpm")));
    wxBitmap itemtool9BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL6, _("Window Filters"), itemtool9Bitmap, itemtool9BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    wxBitmap itemtool10Bitmap(itemPanel1->GetBitmapResource(wxT("images/runprog.xpm")));
    wxBitmap itemtool10BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL7, _("Scripts"), itemtool10Bitmap, itemtool10BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    m_MainToolbar->EnableTool(ID_TOOL7, false);
    wxBitmap itemtool11Bitmap(itemPanel1->GetBitmapResource(wxT("images/gauges.xpm")));
    wxBitmap itemtool11BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL8, _("Gauges"), itemtool11Bitmap, itemtool11BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    m_MainToolbar->EnableTool(ID_TOOL8, false);
    wxBitmap itemtool12Bitmap(itemPanel1->GetBitmapResource(wxT("nfs_mount.xpm")));
    wxBitmap itemtool12BitmapDisabled;
    m_MainToolbar->AddTool(ID_TOOL16, _("FTP"), itemtool12Bitmap, itemtool12BitmapDisabled, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL);
    m_MainToolbar->Realize();
    itemPanel1->GetAuiManager().AddPane(m_MainToolbar, wxAuiPaneInfo()
        .ToolbarPane().Name(_T("Pane1")).Top().MinSize(wxSize(-1, 50)).Layer(10).LeftDockable(false).RightDockable(false).BottomDockable(false).CaptionVisible(false).CloseButton(false).DestroyOnClose(false).Resizable(false).Gripper(true));

    m_Main = new wxMudAuiNotebook( itemPanel1, ID_AUINOTEBOOK, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_EXTERNAL_MOVE|wxAUI_NB_SCROLL_BUTTONS|wxAUI_NB_CLOSE_BUTTON );
    itemPanel1->GetAuiManager().AddPane(m_Main, wxAuiPaneInfo()
        .Name(_T("Pane2")).Centre().CloseButton(false).DestroyOnClose(false).Resizable(true).MaximizeButton(true));

    m_Sub = new wxMudAuiNotebook( itemPanel1, ID_AUINOTEBOOK1, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_EXTERNAL_MOVE|wxAUI_NB_SCROLL_BUTTONS|wxAUI_NB_CLOSE_BUTTON );
    itemPanel1->GetAuiManager().AddPane(m_Sub, wxAuiPaneInfo()
        .Name(_T("Pane3")).Bottom().MinSize(wxSize(600, 140)).CloseButton(false).DestroyOnClose(false).Resizable(true).MaximizeButton(true));

    GetAuiManager().Update();

////@end wxAuiPanel content construction

wxFont defaultFont;
#ifdef WIN32
defaultFont.SetNativeFontInfoUserDesc(pConfig->Read(wxT("/Font/Default"),wxT("courier new 10 windows-1252")));
#else
defaultFont.SetNativeFontInfoUserDesc(pConfig->Read(wxT("/Font/Default"),wxT("Monospace 12")));
#endif

wxTextAttr defaultStyle(wxColour(pConfig->Read(wxT("/Colours/DefaultText"),wxT("rgb(255, 255, 255)"))), 
    wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))), defaultFont);
setDefaultFont(defaultStyle);
setBackgroundColour(wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))));

pConfig->SetPath(wxT("/Colours"));
pConfig->Write(_T("DefaultText"),(defaultStyle.GetTextColour()).GetAsString());
pConfig->Write(_T("DefaultBackground"),(defaultStyle.GetBackgroundColour()).GetAsString());
pConfig->Write(wxT("/Font/Default"),(defaultFont.GetNativeFontInfoUserDesc()));
pConfig->Flush();
m_Sub->SetPageText(0,wxT("Talk"));
((wxMudTextCtrl*)(m_Sub->GetPage(0)))->windowName = wxT("Talk");
m_Sub->Update();
(mudTextWindows[1]->filterList).Add( wxT("tell"));
(mudTextWindows[1]->filterList).Add( wxT("say"));
(mudTextWindows[1]->filterList).Add( wxT("exclaim"));
(mudTextWindows[1]->filterList).Add( wxT("whisper"));
(mudTextWindows[1]->filterList).Add( wxT("ask"));
}


/*
 * Should we show tooltips?
 */
 
bool wxAuiPanel::ShowToolTips()
{
    return true;
}

/*
 * Get bitmap resources
 */

wxBitmap wxAuiPanel::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin wxAuiPanel bitmap retrieval
    wxUnusedVar(name);
    if (name == _T("images/connect.xpm"))
    {
        wxBitmap bitmap(connect_xpm);
        return bitmap;
    }
    else if (name == _T("images/connect_greyed.xpm"))
    {
        wxBitmap bitmap(connect_greyed_xpm);
        return bitmap;
    }
    else if (name == _T("images/disconnect.xpm"))
    {
        wxBitmap bitmap(disconnect_xpm);
        return bitmap;
    }
    else if (name == _T("images/disconnect_greyed.xpm"))
    {
        wxBitmap bitmap(disconnect_greyed_xpm);
        return bitmap;
    }
    else if (name == _T("images/cog.xpm"))
    {
        wxBitmap bitmap(cog_xpm);
        return bitmap;
    }
    else if (name == _T("images/add_top.xpm"))
    {
        wxBitmap bitmap(add_top_xpm);
        return bitmap;
    }
    else if (name == _T("images/add_bottom.xpm"))
    {
        wxBitmap bitmap(add_bottom_xpm);
        return bitmap;
    }
    else if (name == _T("images/add_float.xpm"))
    {
        wxBitmap bitmap(add_float_xpm);
        return bitmap;
    }
    else if (name == _T("images/filter.xpm"))
    {
        wxBitmap bitmap(filter_xpm);
        return bitmap;
    }
    else if (name == _T("images/runprog.xpm"))
    {
        wxBitmap bitmap(runprog_xpm);
        return bitmap;
    }
    else if (name == _T("images/gauges.xpm"))
    {
        wxBitmap bitmap(gauges_xpm);
        return bitmap;
    }
    else if (name == _T("nfs_mount.xpm"))
    {
        wxBitmap bitmap(nfs_mount_xpm);
        return bitmap;
    }
    return wxNullBitmap;
////@end wxAuiPanel bitmap retrieval
}

/*
 * Get icon resources
 */

wxIcon wxAuiPanel::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin wxAuiPanel icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end wxAuiPanel icon retrieval
}


/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL
 */

void wxAuiPanel::OnToolClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL in wxAuiPanel.
    // Before editing this code, remove the block markers.
    QuickConnect* window = new QuickConnect(this);
    int returnValue = window->ShowModal();
    window->Destroy();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL in wxAuiPanel.

    if (returnValue == wxID_OK){
        static wxSocketClient * client = new wxSocketClient;
        client->SetEventHandler(*this, SOCKET_ID);
        client->SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
        client->Notify(true);
        // Wait for the connection event
        wxIPV4address * addr = new wxIPV4address;
        addr->Hostname(pConfig->Read(wxT("/QuickConnect/Server"), wxEmptyString).wc_str());
        addr->Service((pConfig->Read(wxT("/QuickConnect/Port"),wxEmptyString)).wc_str());
        client->Connect(*addr, false);
        if (client->Error()){
            //this may need checking
            wxMessageBox(wxT("error"));
        }else{
        //disable connect and enable disconnect button.
        
          static const telnet_telopt_t my_telopts[] = {
            { TELNET_TELOPT_ECHO,      TELNET_WILL, TELNET_DONT },
            { TELNET_TELOPT_TTYPE,     TELNET_WONT, TELNET_DONT },
            { TELNET_TELOPT_COMPRESS2, TELNET_WONT, TELNET_DONT },
            { TELNET_TELOPT_ZMP,       TELNET_WONT, TELNET_DONT },
            { TELNET_TELOPT_MSSP,      TELNET_WONT, TELNET_DONT },
            { TELNET_TELOPT_BINARY,    TELNET_WONT, TELNET_DONT },
            { TELNET_TELOPT_NAWS,      TELNET_WONT, TELNET_DONT },
            { -1, 0, 0 }
          };
        
        telnet_init(&myTelnet_t, my_telopts, telnet_event_handler, 0, client);
                
        
        mudConnected = true;
        
        }
        commandLine->SetFocus();
    }
 
}


/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL2
 */

void wxAuiPanel::OnPrefsClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL2 in wxAuiPanel.
    // Before editing this code, remove the block markers.
    Preferences* window = new Preferences(this);
    int returnValue = window->ShowModal();
    window->Destroy();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL2 in wxAuiPanel. 

//read string from config
    wxFont defaultFont;
    defaultFont.SetNativeFontInfoUserDesc(pConfig->Read(wxT("/Font/Default")));
    wxTextAttr defaultStyle(wxColour(pConfig->Read(wxT("/Colours/DefaultText"),wxT("rgb(255, 255, 255)"))), 
        wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))), defaultFont);
    setDefaultFont(defaultStyle);

}


static void telnet_event_handler(telnet_t *telnet, telnet_event_t *ev,
		void *user_data) {
	wxSocketBase* client = (wxSocketBase *)user_data;
//wxMessageBox(wxT("test"));
	switch (ev->type) {
	/* data received */
	case TELNET_EV_DATA:

        displayOutput(ev->buffer, ev->size);
		break;
	/* data must be sent */
	case TELNET_EV_SEND:
		//_send(sock, ev->buffer, ev->size);
        client->Write(ev->buffer, ev->size);
		break;
	/* request to enable remote feature (or receipt) */
	case TELNET_EV_WILL:
		/* we'll agree to turn off our echo if server wants us to stop */
		if (ev->telopt == TELNET_TELOPT_ECHO)
		//	do_echo = 0;
		break;
	/* notification of disabling remote feature (or receipt) */
	case TELNET_EV_WONT:
		if (ev->telopt == TELNET_TELOPT_ECHO)
		//	do_echo = 1;
        //Possibly call a function in wxCommandLine to enable/disable echo
		break;
	/* request to enable local feature (or receipt) */
	case TELNET_EV_DO:
		break;
	/* demand to disable local feature (or receipt) */
	case TELNET_EV_DONT:
		break;
	/* respond to particular subnegotiations */
	case TELNET_EV_SUBNEGOTIATION:
		/* if they just asked for our terminal type, response with it */
		/* respond with our terminal type */
		if (ev->telopt == TELNET_TELOPT_TTYPE &&
				ev->argc >= 1 && ev->argv[0][0] == TELNET_TTYPE_SEND) {
			telnet_format_sb(telnet, TELNET_TELOPT_TTYPE, 1,
					TELNET_TTYPE_IS, getenv("TERM"));
		}
		break;
	/* error */
	case TELNET_EV_ERROR:
		fprintf(stderr, "ERROR: %s\n", ev->buffer);
		exit(1);
	default:
		/* ignore */
		break;
	}
}


 void wxAuiPanel::OnSocketEvent(wxSocketEvent& event){
    wxSocketBase * sock = event.GetSocket();
    char buf[512];
    switch (event.GetSocketEvent()){
        case wxSOCKET_CONNECTION:
        {
            m_MainToolbar->EnableTool(ID_TOOL, false);
            m_MainToolbar->EnableTool(ID_TOOL1, true);
            m_MainToolbar->Update();
            ((wixtin*)(this->GetParent()))->m_Status->SetStatusText(wxT("Connected!"));
            break;
        }
        case wxSOCKET_INPUT:
        {
            sock->Read(buf, sizeof(buf));
            telnet_recv(&myTelnet_t, buf, sock->LastCount());
            while (sock->LastCount() == 512){
                sock->Read(buf, sizeof(buf));
                telnet_recv(&myTelnet_t, buf, sock->LastCount());    
            }
            break;
        }
        case wxSOCKET_LOST:
        {
            ((wixtin*)(this->GetParent()))->m_Status->SetStatusText(wxT("Disconnected!"));
            m_MainToolbar->EnableTool(ID_TOOL, true);
            m_MainToolbar->EnableTool(ID_TOOL1, false);
            m_MainToolbar->Update();
            sock->Destroy();
            telnet_free(&myTelnet_t);
            mudConnected = false;
            break;
        }
    }
}




/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL3
 */

void wxAuiPanel::OnAddTopClick( wxCommandEvent& event )
{
    wxMudTextCtrl* newPage = new wxMudTextCtrl( m_Main, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    mudTextWindows.Add(newPage);
    newPage->windowName = wxT("New Tab");
    wxFont defaultFont;
    defaultFont.SetNativeFontInfoUserDesc(pConfig->Read(wxT("/Font/Default")));
    wxTextAttr defaultStyle(wxColour(pConfig->Read(wxT("/Colours/DefaultText"),wxT("rgb(255, 255, 255)"))), 
    wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))), defaultFont);
    setDefaultFont(defaultStyle);
    setBackgroundColour(wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))));
    m_Main->AddPage(newPage, _("New Tab"), true);
}


//TODO CHANGE IDS and set name

/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL4
 */

void wxAuiPanel::OnAddBottomClick( wxCommandEvent& event )
{
    wxMudTextCtrl* newPage = new wxMudTextCtrl( m_Main, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    mudTextWindows.Add(newPage);
    newPage->windowName = wxT("New Tab");
    wxFont defaultFont;
    defaultFont.SetNativeFontInfoUserDesc(pConfig->Read(wxT("/Font/Default")));
    wxTextAttr defaultStyle(wxColour(pConfig->Read(wxT("/Colours/DefaultText"),wxT("rgb(255, 255, 255)"))), 
    wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))), defaultFont);
    setDefaultFont(defaultStyle);
    setBackgroundColour(wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))));
    m_Sub->AddPage(newPage, _("Tab"), true);
}


/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL6
 */

void wxAuiPanel::OnFilterEditClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL6 in wxAuiPanel.
    // Before editing this code, remove the block markers.
    WindowFilters* window = new WindowFilters(this);
    window->Show(true);
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL6 in wxAuiPanel. 
}


/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL5
 */

void wxAuiPanel::OnNewFloatWindowClick( wxCommandEvent& event )
{
    wxString newName = wxGetTextFromUser(wxEmptyString, wxT("Enter a name for the floating window:"));
    if (newName == wxEmptyString){
        return;
    }
    wxMudTextCtrl* newPage = new wxMudTextCtrl( m_Main, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    mudTextWindows.Add(newPage);
    newPage->windowName = newName;
    wxFont defaultFont;
    defaultFont.SetNativeFontInfoUserDesc(pConfig->Read(wxT("/Font/Default")));
    wxTextAttr defaultStyle(wxColour(pConfig->Read(wxT("/Colours/DefaultText"),wxT("rgb(255, 255, 255)"))), 
    wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))), defaultFont);
    setDefaultFont(defaultStyle); 
    setBackgroundColour(wxColour(pConfig->Read(wxT("/Colours/DefaultBackground"),wxT("rgb(0, 0, 0)"))));
    GetAuiManager().AddPane(newPage, wxAuiPaneInfo().Name(newName).Bottom().MinSize(wxSize(400, 140)).CloseButton(true).DestroyOnClose(true).Resizable(true).MaximizeButton(true).Floatable().Float().CaptionVisible(true).Caption(newName));
    GetAuiManager().Update();
}


void wxAuiPanel::OnTextUpdateEvent( wxCommandEvent& event ){
    (((wixtin*) (this->GetParent()))->m_InputBar)->AddPendingEvent(event);
}


/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL1
 */

void wxAuiPanel::OnDisconnectClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL1 in wxAuiPanel.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL1 in wxAuiPanel. 
}


/*
 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL16
 */

void wxAuiPanel::OnFTPClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL16 in wxAuiPanel.
    // Before editing this code, remove the block markers.
    FTPEditor* window = new FTPEditor(this);
    window->Show(true);
////@end wxEVT_COMMAND_MENU_SELECTED event handler for ID_TOOL16 in wxAuiPanel. 
}

